<?php
/**
 * Created by PhpStorm.
 * User: 68008000
 * Date: 2017/11/16
 * Time: 23:44
 */

namespace app\common\model;


use think\Model;

class Link extends Model
{
    //连接数据库link
    protected $table= 'link';
    protected $pk= 'lid';

    protected $auto = ['addtime']; //添加时间
    protected function setAddTimeAttr()
    {
        return time();
    }
    //主页
    public function index(){

    }
    //添加
    public function add($data){
        //1添加文章数据库
        $result = $this->validate(true)->save($data);
        if(false === $result){
            // 验证失败 输出错误信息
            return ['valid'=>0,'msg'=>$this->getError()];
        }else{

            return ['valid'=>1,'msg'=>'添加成功'];
        }
    }
    //编辑
    public function edit($data){
        $lid=input('param.lid');
        $result = $this->validate(true)->save($data,['lid' => $lid]);
        if(false === $result){
            // 验证失败 输出错误信息
            return ['valid'=>0,'msg'=>$this->getError()];
        }else{

            return ['valid'=>1,'msg'=>'添加成功'];
        }
    }
    //删除
    public function del($lid){
        $res=$this::where('lid',$lid)->delete();
        if(false === $res){
            // 验证失败 输出错误信息
            return ['valid'=>0,'msg'=>$this->getError()];
        }else{
            return ['valid'=>1,'msg'=>'删除成功'];
        }

    }
}